package com.globalwave.util
{
	import mx.controls.Alert;
	import mx.core.UIComponent;
	import mx.events.ValidationResultEvent;
	import mx.validators.Validator;
	
	public class ValidateUtil
	{
		public static function checkForm(validators :Array) :Boolean {
		  
  	  var validatorResults:Array = Validator.validateAll(validators);
      //长度为0表示所有验证通过
      if(validatorResults.length == 0){
          return true ;
      }else{
          //将光标定位到第一个错误
          var v:ValidationResultEvent = validatorResults[0] as ValidationResultEvent;
          var ui: UIComponent = (v.target.source as UIComponent) ;
          ui.setFocus();
          Alert.show(ui.errorString) ; 
          return false ;
      }
			/*
			for (var i : int = 0 ; i < validators.length ; i ++) {
				var validator : Validator = Validator(validators[i]) ;
				if (validator.validate().type ==ValidationResultEvent.INVALID) {
					return false ;
				}
			}
       return true ;
			*/
		}
	}
}